// pages/logIn/logIn.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    utype:0,
    name:'',
    password:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var utype = options.utype;
    this.setData({
      utype:utype
    });
  },

  getName:function (e) {
    console.log(e)
    var name = e.detail.value;
    this.setData({
      name:name
    });
  },
  getPassword: function (e) {
    console.log(e)
    var password = e.detail.value;
    this.setData({
      password: password
    });
  },

  bindFormSubmit:function (e) {
    var that = this;
    wx.request({
      url: app.d.ceshiUrl + '/Api/User/login',
      method: "post",
      data: {
        uid: app.d.userId,
        utype:that.data.utype,
        name:that.data.name,
        password:that.data.password
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
         wx.switchTab({
           url: '../index/index',
           success: function (e) {
             app.d.utype = that.data.utype
           }  
         })
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})